//
//  XJLeftMenuController.m
//  EPA
//
//  Created by lanou3g on 16/4/15.
//  Copyright © 2016年 ZhangXJ. All rights reserved.
//


#define kButtonWidth  ([UIScreen mainScreen].bounds.size.width * 0.8 - 120)/ 5
#define kMenuViewWidth  [UIScreen mainScreen].bounds.size.width * 0.8
#define kMunuViewHeight  [UIScreen mainScreen].bounds.size.height
#define kColor    (37 / 255.0)

#import "XJLeftMenuController.h"
#import "XJ_MenuViewController.h"

@interface XJLeftMenuController () <UITableViewDataSource,UITableViewDelegate>
@property (strong, nonatomic) UITableView *menuTableView;
@property (strong, nonatomic) NSMutableArray *menuArray;

@end

@implementation XJLeftMenuController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.frame = CGRectMake(-kMenuViewWidth, 0, kMenuViewWidth, kMunuViewHeight);
    self.menuTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kMenuViewWidth, kMunuViewHeight) style:UITableViewStylePlain];
    
    self.menuTableView.separatorStyle =  UITableViewCellSeparatorStyleNone;
    self.menuTableView.directionalLockEnabled = YES;
    self.menuTableView.bounces = NO;
    
    self.menuTableView.tableHeaderView = [self headerView];
    self.menuTableView.tableFooterView = [self footerView];
    
    self.menuTableView.delegate = self;
    self.menuTableView.dataSource = self;
    [self.view addSubview:self.menuTableView];
}

#pragma mark - 头部 尾部视图
- (UIView *)headerView {
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 63)];
    
    UIButton *findButton = [UIButton buttonWithType:UIButtonTypeCustom];
    findButton.frame = CGRectMake(kButtonWidth, 24, 30, 30);
    [findButton setBackgroundImage:[UIImage imageNamed:@"放大镜"] forState:UIControlStateNormal];
    [headerView addSubview:findButton];
    
    UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
    downloadButton.frame = CGRectMake(kButtonWidth * 2 + 30, 24, 30, 30);
    [downloadButton setBackgroundImage:[UIImage imageNamed:@"下载"] forState:UIControlStateNormal];
    [headerView addSubview:downloadButton];
    
    UIButton *thumbButton = [UIButton buttonWithType:UIButtonTypeCustom];
    thumbButton.frame = CGRectMake(kButtonWidth * 3 + 60, 24, 30, 30);
    [thumbButton setBackgroundImage:[UIImage imageNamed:@"点赞"] forState:UIControlStateNormal];
    [headerView addSubview:thumbButton];
    
    
    UIButton *chatButton = [UIButton buttonWithType:UIButtonTypeCustom];
    chatButton.frame = CGRectMake(kButtonWidth * 4 + 90, 24, 30, 30);
    [chatButton setBackgroundImage:[UIImage imageNamed:@"聊天"] forState:UIControlStateNormal];
    [headerView addSubview:chatButton];
    
    headerView.backgroundColor = [UIColor colorWithRed:kColor green:kColor blue:kColor alpha:1];
    return headerView;
}

- (UIView *)footerView {
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 200)];
    
    footerView.backgroundColor = [UIColor colorWithRed:kColor green:kColor blue:kColor alpha:1];
    return footerView;
}


- (NSMutableArray *)menuArray {
    if (!_menuArray) {
        _menuArray = @[@"未登录",@"今日·TODAY",@"电台·RADIO",@"阅读·READING",@"话题·TOPIC",@"音乐·MUSIC",@"良品·PRODUCTS",@"",@"订阅·SUBSRIPTIONS",@"设置·SETTING"].mutableCopy;
    }
    return _menuArray;
}

#pragma mark - UITableViewDataSource
// 数据源代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.menuArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *reuserID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuserID];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuserID];
    }
    if (indexPath.row == 0) {
        
        UIView *buttonLine = [[UIView alloc] initWithFrame:CGRectMake(10, 0, kMenuViewWidth - 20, 3)];
        buttonLine.backgroundColor = [UIColor lightGrayColor];
        [cell.contentView addSubview:buttonLine];
        
        UIView *userLine = [[UIView alloc] initWithFrame:CGRectMake(10, 98, kMenuViewWidth - 20, 1)];
        userLine.backgroundColor = [UIColor lightGrayColor];
        [cell.contentView addSubview:userLine];
        
        cell.imageView.image = [UIImage imageNamed:@"账户"];
        cell.textLabel.text = self.menuArray[0];
    }else if(indexPath.row == 7) {
        UIView *setLine = [[UIView alloc] initWithFrame:CGRectMake(10, 9.5, kMenuViewWidth - 20, 1)];
        setLine.backgroundColor = [UIColor lightGrayColor];
        [cell.contentView addSubview:setLine];
    }else {
    cell.textLabel.text = self.menuArray[indexPath.row];
    }
    
    cell.textLabel.textColor = [UIColor grayColor];
    cell.backgroundColor = [UIColor colorWithRed:kColor green:kColor blue:kColor alpha:1];
    cell.textLabel.highlightedTextColor = [UIColor whiteColor];
   
    UIView *backView = [[UIView alloc] init];
    backView.backgroundColor = [UIColor clearColor];
    cell.selectedBackgroundView = backView;
    cell.multipleSelectionBackgroundView = nil;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return 100.0;
    }else if(indexPath.row == 7) {
        return 20;
    }
    return 50;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // 取消选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
   
    // 关闭抽屉
    [[XJ_MenuViewController getMenuViewController] hideLeftViewController];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
